package com.muse.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer status;
    private String msg;
    private T data;

    private Pagination pagination;


    public static <T> Result<T> result(T t) {
        return new Result<T>(t);
    }

    public Result(T data) {
        this.data = data;
    }


    public static Result<?> success() {
        Result<?> result = new Result<>();
        result.setStatus(0);
        result.setMsg("成功");
        return result;
    }

    public static <T> Result<T> success(T t) {
        Result<T> result = new Result<>();
        result.setStatus(0);
        result.setMsg("成功");
        result.setData(t);
        return result;
    }

    public static Result<?> success(String message) {
        Result<?> result = new Result<>();
        result.setStatus(0);
        result.setMsg(message);
        return result;
    }

    public static <T> Result<T> success(String message, T t) {
        Result<T> result = new Result<>();
        result.setStatus(0);
        result.setMsg(message);
        result.setData(t);
        return result;
    }


    public static Result<?> failure() {
        Result<?> result = new Result<>();
        result.setStatus(1);
        result.setMsg("失败");
        return result;
    }

    public static <T> Result<T> failure(T t) {
        Result<T> result = new Result<>();
        result.setStatus(1);
        result.setMsg("失败");
        result.setData(t);
        return result;
    }

    public static Result<?> failure(String message) {
        Result<?> result = new Result<>();
        result.setStatus(1);
        result.setMsg(message);
        return result;
    }

    public static <T> Result<T> failure(String message, T t) {
        Result<T> result = new Result<>();
        result.setStatus(1);
        result.setMsg(message);
        result.setData(t);
        return result;
    }


    public Result<T> pagination(Pagination pagination) {
        this.pagination = pagination;
        return this;
    }

    public Result<T> pagination(int page, int pageSize, int total) {
        this.pagination = new Pagination(page, pageSize, total);
        return this;
    }

    public Pagination getPagination() {
        return this.pagination;
    }


    public Result<T> setPagination(Pagination pagination) {
        this.pagination = pagination;
        return this;
    }


    public static class Pagination {
        private int page;
        private int pageSize;
        private int total;

        public Pagination() {
        }

        public Pagination(int page, int pageSize, int total) {
            this.page = page;
            this.pageSize = pageSize;
            this.total = total;
        }

        public int getPage() {
            return this.page;
        }

        public Pagination setPage(int page) {
            this.page = page;
            return this;
        }

        public int getPageSize() {
            return this.pageSize;
        }

        public Pagination setPageSize(int pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public int getTotal() {
            return this.total;
        }

        public Pagination setTotal(int total) {
            this.total = total;
            return this;
        }
    }
}



